package com.evil.kingdom.pojo.entity.action;

import cn.hutool.core.util.ObjectUtil;
import com.evil.kingdom.pojo.dto.person.base.PersonDto;
import com.evil.kingdom.pojo.entity.base.Fight;
import com.evil.kingdom.pojo.entity.base.Loyalty;
import lombok.Getter;
import lombok.Setter;

/**
 * 战斗-个人
 *
 * @author liyang
 * @date 2024-06-25 11:24
 */
@Getter
@Setter
public class BattlePerson<T extends PersonDto> implements Loyalty {

    private T base;

    /**
     * 忠诚
     */
    private Integer loyalty;

    /**
     * 归属
     */
    private String belong;

    public BattlePerson(T t, Fight addition) {
        this.base = t;
        this.loyalty = 100;
        this.belong = t.getName();
        this.base.addition(addition);
        if (t instanceof Loyalty l) {
            this.loyalty = l.getLoyalty();
            this.belong = l.getBelong();
        }
    }

    public boolean checkHostile(BattlePerson<?> that) {
        return ObjectUtil.equal(belong, that.getBelong());
    }

    @Override
    public boolean equals(Object o) {
        if (null == o) return false;
        if (getClass() != o.getClass()) return false;
        BattlePerson<?> thatPerson = (BattlePerson<?>) o;
        return this.base.equals(thatPerson.base);
    }

    @Override
    public int hashCode() {
        return base.hashCode();
    }
}
